
layui.use(['form', 'xmSelect', 'upload', 'laydate'], function () {
    var form = layui.form;
    var layer = layui.layer,myInviteeId='',myInviteeList=[]


    $('#mySelect').attr("disabled",true);
    if($('#infoType').val()=='push'){
        AjaxGet( '/userInterview/getUserInterviewAunt',{
            inviterId:$('#inviterId').val(),
            inviteeId:$('#inviteeId').val(),
            projectId:$('#projectId').val(),
            id:$('#userId').val()
        }).then(function (response){
            if(response.code=='0'){
                myDataList=response.data
                //设置select
                $('#mySelect').empty();
                $('#mySelect').append($('<option>', {
                    value: '',
                    text: '请选择姓名'
                }))
                myInviteeList=response.data
                response.data.forEach(item=>{
                    $('#mySelect').append($('<option>', {
                        value: item.sysUserid,
                        text: item.name+'-'+item.mobile,
                        selected:$('#inviteeId').val().toString()==item.sysUserid.toString()
                    }))
                    if($('#inviteeId').val().toString()==item.sysUserid.toString()){
                        //设置选中
                        $('#projectName').html(item.projectName)
                        $('#inviterPhone').html(item.mobile)
                        myInviteeId=item.sysUserid
                    }
                })
                if($('#infoType').val() == 'push'){
                    $('#mySelect').attr("disabled",false);
                }else{
                    console.log('$(\'#mySelect\').next()',$('#mySelect').next())
                }
                form.render('select');
                selectInput($('#mySelect'),10)
            }
        }).catch(error => {
            layer.msg(error.msg)
        })
    }
    form.on('radio(demo-radio-filter)', function(data){

        if(data?.elem?.value=='2'){
            $('#refuseReason').show()
        }else {
            $('#refuseReason').hide()
            $("textarea[name='rejectReasion']").val('');
        }

    });
    form.on('select(demo-select-filter)', function(data){
        //修改 fw3==>fw10
        if(data.value!=""){
            let myitem=myInviteeList.find(item=>item.sysUserid==data.value)
            $('#projectName').html('<span style="color: rgb(117 117 117);">'+myitem.projectName+'</span>')
            $('#inviterPhone').html('<span style="color: rgb(117 117 117);">'+myitem.mobile+' </span>')
            myInviteeId=myitem.sysUserid
        }else {
            $('#projectName').html('<span style="color: rgb(117 117 117);">请先选择姓名</span>')
            $('#inviterPhone').html('<span style="color: rgb(117 117 117);">请先选择姓名</span>')
        }
    });
    //提交事件
    form.on('submit(submit)', function (data) {

        if ($('#infoType').val() == 'push') {
            AjaxPost('/userInterview/userInterviewPush', {
                id: $('#userId').val(),
                inviteeId:myInviteeId
            }).then(function (response) {
                parent.layer.msg("操作成功");
                var index = parent.layer.getFrameIndex(window.name); // 获取窗口索引
                parent.layer.close(index);
                parent.load();
            }).catch(error => {
                layer.msg(error.msg)
            })
        }else if($('#infoType').val() == 'info') {
            var index = parent.layer.getFrameIndex(window.name); // 获取窗口索引
            parent.layer.close(index);
            parent.load();
        }else if($('#infoType').val() == 'edit') {

            AjaxPost('/userInterview/updateUserInterview ', {
                id: $('#userId').val(),
                result:parseInt(data.field.result),
                rejectReasion:parseInt(data.field.result)==1?'':data.field.rejectReasion
            }).then(function (response) {
                parent.layer.msg("操作成功");
                var index = parent.layer.getFrameIndex(window.name); // 获取窗口索引
                parent.layer.close(index);
                parent.load();
            }).catch(error => {
                layer.msg(error.msg)
            })
        }

    });

});

